<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>计算天数</title>
  </head>
  <body>
    <script>
      //让用户输入要查询的年月日份 用3个变量储存
      var year = parseInt(prompt("输入年份"));
      var month = parseInt(prompt("输入月份"));
      var day = parseInt(prompt("输入日期"));
      var allDays = 0; //所有天数
      for (var i = 1; i < month; i++) {
        if (
          i === 1 ||
          i === 3 ||
          i === 5 ||
          i === 7 ||
          i === 8 ||
          i === 10 ||
          i === 12
        ) {
          allDays += 31;
        } else if (i === 4 || i === 6 || i === 9 || i === 11) {
          allDays += 30;
        } else {
          if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
            allDays += 29;
          } else {
            allDays += 28;
          }
        }
      }
      allDays = day + allDays;
      alert(year + "年" + month + "月" + day + "日" + "是第" + allDays + "天");
    </script>
  </body>
</html>
